﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace QunYing.Web.market
{
    public partial class msg : System.Web.UI.Page
    {
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Repeater rp = ((Repeater)Master.FindControl("NavRepeater"));
                rp.DataSource = NavData();
                rp.DataBind();
            }
        }
        /// <summary>
        /// 快捷导航数据
        /// </summary>
        private DataTable NavData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("name");
            dt.Columns.Add("url");
            dt.Rows.Add("留言建议", "");
            return dt;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GVBind();
            }
        }
        /// <summary>
        /// 数据绑定
        /// </summary>
        private void GVBind()
        {
            string userName = ((ArrayList)Session["userInfo"])[0].ToString();
            BLL.LeaveMsg msg = new BLL.LeaveMsg();
            DataTable dt = msg.GetMsg(userName);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Session["userInfo"] == null)
            {
                Response.Redirect("~/Login.aspx");
            }

            BLL.LeaveMsg msg = new BLL.LeaveMsg();
            Model.LeaveMsg model = new Model.LeaveMsg();
            model.用户ID = ((ArrayList)Session["userInfo"])[0].ToString();
            model.类型 = RadioButtonList1.SelectedValue;
            model.回复内容 = txtMsg.Text.Trim().Replace("\n", "<br/>");
            int i = msg.Add(model);
            if (i > 0)
            {
                MessageBox.Show(UpdatePanel1, "留言成功!");
                txtMsg.Text = string.Empty;
                GridView1.PageIndex = 0;
                GVBind();
            }
            else
            {
                MessageBox.Show(UpdatePanel1, "留言失败,请重试!");
            }
            
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GVBind();
        }
    }
}
